package com.ea.eadp.nexus.test.workflow;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.WebDriver;

public abstract class WorkflowElement {
    protected Log log = LogFactory.getLog( getClass() );
    
    public boolean needInit = true;
    public boolean needDoPreVerification = true;
    public boolean needDoAction = true;
    public boolean needDoVerification = true;
    public boolean needMoveNext = true;
    
    public String getDescription() {
        return "base work flow";
    }
    
    public WorkflowElementArgument args;
    
    protected WebDriver driver = null;
    
    public WorkflowElement(WebDriver driver) {
        this(driver, null);
    }
    
    public WorkflowElement(WebDriver driver, WorkflowElementArgument args) {
        this.driver = driver;
        if (null != args) {
            this.args = args;
        }
        else {
            this.args = new WorkflowElementArgument();
        }
    }
    
    public void execute() {
        log.info("====== Action Start: " + getDescription() + " ======");
        
        if (needInit) {
            init();
        }
        if (needDoPreVerification) {
            doPreVerification();
        }
        if (needDoAction) {
            doAction();
        }
        if (needDoVerification) {
            doVerification();
        }
        if (needMoveNext) {
            moveNext();
        }
        
        log.info("====== Action Complete: " + getDescription() + " ======");
    }
    
    public void init() {}
    
    public void doPreVerification() {}
    
    public void doAction() {}
    
    public void doVerification() {}
    
    public void moveNext() {}
    
    protected void navigate(String url) {
        log.info("Navigate to " + url);
        driver.navigate().to(url);
    }
    
}
